// uhttp.js
const config = {
  baseUrl: '',
  method: 'POST',
  dataType: 'json',
  showLoading: true,
  loadingText: '请求中...',
  loadingTime: 800,
  originalData: false,
  loadingMask: true,
  header: {
    'content-type': 'application/json;charset=UTF-8'
  },
}

const install = (Vue, vm) => {
  Vue.prototype.$u.http.setConfig(config)

  // 请求拦截
  Vue.prototype.$u.http.interceptor.request = (config) => {
    if (token) {
      config.header.Authorization = 'Bearer ' + token
    } else {
      config.header.Authorization = ''
    }

    return config
  }

  // 响应拦截
  Vue.prototype.$u.http.interceptor.response = (res) => {
    if (true) {
      return res.data.result
    } else {
      vm.$u.toast('出了点小问题')
      return false
    }
  }
}

export default {
  install
}
